Various applications require truncation of signed numbers divided by an integer power of two, e.g., 1, 2, 4, 8, 16, etc. Truncation implies integer division with truncation of the result toward 0. For example, 3/2 is truncated to 1, while −3/2 is truncated to −1.
Truncation of unsigned numbers can be achieved by the right shift operation. The number of times right shift has to be performed is equal to the log2 of the denominator. For example, if 13 (01101) is to be truncated by four, log24=2 (10), 01101 is right shifted twice, resulting in 11, or three.
Although the foregoing scheme works for unsigned binary numbers, it does not yield correct results for signed binary numbers. This is because of the fact that in two's complement representation of signed binary numbers, the sign bit (most significant bit) of the numbers carries a negative weight. Thus if 10011 (−13) has to be truncated by 100 (4), the result should be −3. However, the foregoing scheme results in 100 (4).
One way to achieve truncation of signed binary numbers is to convert the signed number to unsigned numbers (preserving the sign information), truncate the unsigned numbers, and apply to sign information. The foregoing adds additional steps of converting each signed number to unsigned number, requiring more processing, and more time.
Further limitations and disadvantages of conventional and traditional approaches will become apparent to one of skill in the art, through comparison of such systems with embodiments presented in the remainder of the present application with references to the drawings.